package com.mr.qa.bo;

import java.util.Date;
import java.util.List;

import com.mr.qa.dao.impl.UserMoneySpendHistoryDAO;
import com.mr.qa.exception.QaException;

public class UserMoneySpendHistory extends BaseBO {
	
	private Integer resourceId;
	private String resourceName;
    private String type;
    private Date date;
    private Integer money;
    private String description;
    private User user;

	public UserMoneySpendHistory() {
		super();
	}
	
	public UserMoneySpendHistory(Date date, Integer money) {
		super();
		this.date = date;
		this.money = money;
	}

	public UserMoneySpendHistory(Integer resourceId, String resourceName,
			String type, Date date, Integer money, String description, User user) {
		super();
		this.resourceId = resourceId;
		this.resourceName = resourceName;
		this.type = type;
		this.date = date;
		this.money = money;
		this.description = description;
		this.user = user;
	}

	public Integer getResourceId() {
		return resourceId;
	}

	public void setResourceId(Integer resourceId) {
		this.resourceId = resourceId;
	}

	public String getResourceName() {
		return resourceName;
	}

	public void setResourceName(String resourceName) {
		this.resourceName = resourceName;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Integer getMoney() {
		return money;
	}

	public void setMoney(Integer money) {
		this.money = money;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
	public List findUserSpendOnly(Integer userId, int page, int recordSize) throws QaException{
		UserMoneySpendHistoryDAO historyDAO = new UserMoneySpendHistoryDAO();
		if(page != 0 && recordSize != 0){
			historyDAO.setPage(page, recordSize);
		}
		return historyDAO.findUserSpend(userId, "money < 0");
	}
	
	public List findUserAwardOnly(Integer userId, int page, int recordSize) throws QaException{
		UserMoneySpendHistoryDAO historyDAO = new UserMoneySpendHistoryDAO();
		if(page != 0 && recordSize != 0){
			historyDAO.setPage(page, recordSize);
		}
		return historyDAO.findUserSpend(userId, "money > 0");
	}
	
	public Integer countUserSpendOnly(Integer userId) {
		UserMoneySpendHistoryDAO historyDAO = new UserMoneySpendHistoryDAO();
		return historyDAO.countUserSpend(userId, "money < 0");
	}
	
	public Integer countUserAwardOnly(Integer userId) {
		UserMoneySpendHistoryDAO historyDAO = new UserMoneySpendHistoryDAO();
		return historyDAO.countUserSpend(userId, "money > 0");
	}
	
	public Integer getUserSpendOnlyAmount(Integer userId) throws QaException{
		UserMoneySpendHistoryDAO historyDAO = new UserMoneySpendHistoryDAO();
		return historyDAO.getUserSpendAmount(userId, "money < 0");
	}
	
	public Integer getUserAwardOnlyAmount(Integer userId) throws QaException{
		UserMoneySpendHistoryDAO historyDAO = new UserMoneySpendHistoryDAO();
		return historyDAO.getUserSpendAmount(userId, "money > 0");
	}
	
	public List getAllAward(int page, int recordSize) throws QaException{
		UserMoneySpendHistoryDAO historyDAO = new UserMoneySpendHistoryDAO();
		historyDAO.setPage(page, recordSize);
		return historyDAO.getSpend("money > 0", "date desc");
	}
	
	public Integer countAllAward() throws QaException{
		UserMoneySpendHistoryDAO historyDAO = new UserMoneySpendHistoryDAO();
		return historyDAO.getSpendCount("money > 0", "date desc");
	}

}
